"""BLE GATT Server constants and UUID definitions."""

import logging
from typing import Final

# Logging configuration
LOG_LEVEL = logging.INFO
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

# BLE Service and Characteristic UUIDs
SERVICE_UUID: Final[str] = "0000FFF0-0000-1000-8000-00805F9B34FB"
CHAR_COMMAND_UUID: Final[str] = "0000FFF1-0000-1000-8000-00805F9B34FB"  # WRITE
CHAR_RESPONSE_UUID: Final[str] = "0000FFF2-0000-1000-8000-00805F9B34FB"  # READ/NOTIFY
CHAR_STATUS_UUID: Final[str] = "0000FFF3-0000-1000-8000-00805F9B34FB"  # NOTIFY
CHAR_NOTIFICATION_UUID: Final[str] = "00002A05-0000-1000-8000-00805F9B34FB"  # NOTIFY - Status notifications

# BLE Advertisement settings
ADV_NAME_PREFIX: Final[str] = "CloudPrinter"
ADV_INTERVAL_MIN: Final[int] = 100  # milliseconds
ADV_INTERVAL_MAX: Final[int] = 1000  # milliseconds
ADV_INTERVAL_DEFAULT: Final[int] = 500  # milliseconds

# Connection settings
MAX_CONNECTIONS: Final[int] = 1  # Single connection only
CONNECTION_TIMEOUT: Final[int] = 300  # 5 minutes in seconds
IDLE_TIMEOUT: Final[int] = 60  # 1 minute of inactivity

# MTU settings
MTU_MIN: Final[int] = 20  # BLE 4.0 minimum
MTU_MAX: Final[int] = 512  # Maximum supported MTU
MTU_DEFAULT: Final[int] = 23  # BLE 4.0 default (20 bytes data + 3 bytes header)

# Protocol settings
FRAGMENT_HEADER_SIZE: Final[int] = 4  # 2 bytes for seq, 2 bytes for total
MAX_FRAGMENT_DATA_SIZE: Final[int] = MTU_DEFAULT - FRAGMENT_HEADER_SIZE
REASSEMBLY_TIMEOUT: Final[int] = 10  # seconds to wait for all fragments

# Performance limits
MAX_CPU_USAGE: Final[float] = 5.0  # Maximum CPU usage percentage
MAX_MEMORY_MB: Final[int] = 30  # Maximum memory usage in MB
STARTUP_TIMEOUT: Final[int] = 3  # Maximum startup time in seconds

# DBus settings
DBUS_SERVICE_NAME: Final[str] = "org.bluez"
DBUS_ADAPTER_INTERFACE: Final[str] = "org.bluez.Adapter1"
DBUS_DEVICE_INTERFACE: Final[str] = "org.bluez.Device1"
DBUS_GATT_MANAGER_INTERFACE: Final[str] = "org.bluez.GattManager1"
DBUS_LE_ADVERTISING_MANAGER_INTERFACE: Final[str] = "org.bluez.LEAdvertisingManager1"
DBUS_LE_ADVERTISEMENT_INTERFACE: Final[str] = "org.bluez.LEAdvertisement1"
DBUS_GATT_SERVICE_INTERFACE: Final[str] = "org.bluez.GattService1"
DBUS_GATT_CHARACTERISTIC_INTERFACE: Final[str] = "org.bluez.GattCharacteristic1"
DBUS_GATT_DESCRIPTOR_INTERFACE: Final[str] = "org.bluez.GattDescriptor1"

# DBus object paths
DBUS_BLUEZ_OBJECT_PATH: Final[str] = "/org/bluez"
DBUS_ADAPTER_PATH_PREFIX: Final[str] = "/org/bluez/hci"
DBUS_APPLICATION_PATH: Final[str] = "/com/cloudprinter/ble"

# Characteristic flags
CHAR_FLAGS_WRITE: Final[list] = ["write", "write-without-response"]
CHAR_FLAGS_READ_NOTIFY: Final[list] = ["read", "notify"]
CHAR_FLAGS_NOTIFY: Final[list] = ["notify"]

# Status codes
STATUS_SUCCESS: Final[int] = 0
STATUS_ERROR: Final[int] = 1
STATUS_INVALID_COMMAND: Final[int] = 2
STATUS_FRAGMENTATION_ERROR: Final[int] = 3
STATUS_TIMEOUT: Final[int] = 4
STATUS_CONNECTION_LIMIT: Final[int] = 5

# Response messages
RESPONSE_PONG: Final[str] = "pong"
RESPONSE_CONNECTED: Final[str] = "connected"
RESPONSE_DISCONNECTED: Final[str] = "disconnected"
RESPONSE_ERROR: Final[str] = "error"